package com.grace.cms.general.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.grace.cms.common.enums.ArticleTypeEnums;
import com.grace.cms.common.enums.OrderEnums;
import com.grace.cms.general.model.enums.ArticleCountSortEnum;
import com.grace.cms.general.taglib.ArticleCountSortTag;
import com.grace.common.core.controller.BaseController;
import com.grace.common.core.domain.AjaxResult;

/**
 * 文章统计排序API控制器
 */
@CrossOrigin
@RestController
@RequestMapping("/{themeName}/api/articleSort")
public class ArticleCountSortApiController extends BaseController {

    @Autowired
    private ArticleCountSortTag articleCountService;

    /**
     * 获取文章的上一篇和下一篇
     */
    @GetMapping("/getPreAndNextArticle/{articleId}")
    public AjaxResult selectPreAndNextArticle(@PathVariable(value = "themeName") String themeName,
            @PathVariable("articleId") long articleId) {
                System.out.println(themeName);
        return AjaxResult.success(articleCountService.selectPreAndNextArticle(articleId, themeName));
    }

    /**
     * 根据分类ID获取排序后的文章列表
     */
    @GetMapping("/listWebArticleOrderByCategoryId/{categoryId}/{pageNum}/{pageSize}/{sort}/{order}")
    public AjaxResult selectWebArticleOrderByCategoryId(@PathVariable(value = "themeName") String themeName,
            @PathVariable("categoryId") long categoryId,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("sort") ArticleCountSortEnum sort,
            @PathVariable("order") OrderEnums order) {
        return AjaxResult
                .success(articleCountService.listWebArticleOrderByCategoryId(themeName, categoryId, pageNum, pageSize,
                        sort, order));
    }

    /**
     * 综合获取排序文章列表
     */
    @GetMapping("/listArticlesVo/{num}/{size}/{articleType}/{categoryId}/{sort}/{order}")
    public AjaxResult listArticlesVo(@PathVariable(value = "themeName") String themeName,
            @PathVariable("num") Integer num,
            @PathVariable("size") Integer pageSize,
            @PathVariable("articleType") ArticleTypeEnums articleType,
            @PathVariable("categoryId") Long categoryId,
            @PathVariable("sort") ArticleCountSortEnum sort,
            @PathVariable("order") OrderEnums order) {
        return AjaxResult.success(articleCountService.listArticlesVo(num, pageSize, articleType, categoryId, themeName, sort, order));
    }

    /**
     * 通过文章类型获取排序文章列表
     */
    @GetMapping("/listArticlesVoByType/{num}/{size}/{articleType}/{sort}/{order}")
    public AjaxResult listArticlesVoByType(@PathVariable(value = "themeName") String themeName,
            @PathVariable("num") Integer num,
            @PathVariable("size") Integer pageSize,
            @PathVariable("articleType") ArticleTypeEnums articleType,
            @PathVariable("sort") ArticleCountSortEnum sort,
            @PathVariable("order") OrderEnums order) {
        return AjaxResult.success(articleCountService.listArticlesVoByType(num, pageSize, articleType, themeName, sort, order));
    }

    /**
     * 获取排序文章列表
     */
    @GetMapping("/listWebArticleOrder/{pageNum}/{pageSize}/{sort}/{order}")
    public AjaxResult listWebArticleOrder(@PathVariable(value = "themeName") String themeName,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("sort") ArticleCountSortEnum sort,
            @PathVariable("order") OrderEnums order) {
        return AjaxResult.success(articleCountService.listWebArticleOrder(pageNum, pageSize, themeName, sort, order));
    }

    /**
     * 通过文章类型获取排序文章列表
     */
    @GetMapping("/listWebArticleOrderByType/{pageNum}/{pageSize}/{articleType}/{sort}/{order}")
    public AjaxResult listWebArticleOrderByType(@PathVariable(value = "themeName") String themeName,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("articleType") Integer articleType,
            @PathVariable("sort") ArticleCountSortEnum sort,
            @PathVariable("order") OrderEnums order) {
        return AjaxResult.success(articleCountService.listWebArticleOrderByType(pageNum, pageSize, articleType, themeName, sort, order));
    }
}
